#include <QApplication>
#include <QPushButton>
#include <QLCDNumber>
#include <QSlider>
#include <QVBoxLayout>
#include <QHBoxLayout>

class CWidget : public QWidget
{
public:
	CWidget(QWidget* parent = 0);
};

CWidget::CWidget(QWidget* parent) : QWidget(parent)
{
	setFixedSize(300, 200);
	setWindowTitle("mywidget");
	
	//QPushButton quitButton("quit no 2!");
	QPushButton* quitButton = new QPushButton(tr("quit no 2"));
	//quitButton.resize(100, 30);
	quitButton->setGeometry(62, 40, 75, 30);
	quitButton->setFont(QFont("Times", 18, QFont::Bold));
	//connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
	connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(quitButton);
	setLayout(layout);
}

class DWidget : public QWidget
{
public:
	DWidget(QWidget* parent = 0);
};

DWidget::DWidget(QWidget* parent) : QWidget(parent)
{
	//QPushButton quitButton("quit no 3!");
	QPushButton* quitButton = new QPushButton(tr("quit no 3"));
	quitButton->resize(100, 30);
	//quitButton.setGeometry(62, 40, 75, 30);
	quitButton->setFont(QFont("Times", 18, QFont::Bold));
	//connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
	connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));

	QLCDNumber* lcd = new QLCDNumber(2);
	lcd->setSegmentStyle(QLCDNumber::Filled);
	QSlider* slider = new QSlider(Qt::Horizontal);
	slider->setRange(0, 99);
	slider->setValue(0);
	connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));

	QVBoxLayout* layout = new QVBoxLayout;
	layout->addWidget(quitButton);
	layout->addWidget(lcd);
	layout->addWidget(slider);
	setLayout(layout);
}

class EWidget : public QWidget
{
public:
	EWidget(QWidget* parent = 0);
};

class LCDRange : public QWidget
{
public:
	LCDRange(QWidget* parent = 0);
};

LCDRange::LCDRange(QWidget* parent) : QWidget(parent)
{
	QLCDNumber* lcd = new QLCDNumber(2);
	lcd->setSegmentStyle(QLCDNumber::Filled);
	QSlider* slider = new QSlider(Qt::Horizontal);
	slider->setRange(0, 99);
	slider->setValue(0);
	connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
	QVBoxLayout* layout = new QVBoxLayout;
	layout->addWidget(lcd);
	layout->addWidget(slider);
	setLayout(layout);
}

EWidget::EWidget(QWidget* parent) : QWidget(parent)
{

	QPushButton* quitButton = new QPushButton(tr("quit no 4"));
	quitButton->setFont(QFont("Times", 18, QFont::Bold));
	connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));

	QGridLayout* grid = new QGridLayout;
	for (int row=0; row<3; ++row) {
		for (int col=0; col<3; ++col) {
			LCDRange* lcd = new LCDRange;
			grid->addWidget(lcd, row, col);
		}
	}
	QVBoxLayout* layout = new QVBoxLayout;
	layout->addWidget(quitButton);
	layout->addLayout(grid);
	setLayout(layout);
}

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

// lat 1
	QPushButton helloButton("hello, world!");
	helloButton.resize(100, 30);
	helloButton.show();

// lat 2
	QPushButton quitButton("quit!");
	//quitButton.resize(100, 30);
	quitButton.setGeometry(10, 40, 180, 40);
	quitButton.setFont(QFont("Times", 18, QFont::Bold));
	QObject::connect(&quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
	quitButton.show();
// lat 3
	QWidget mywindow;
	mywindow.resize(300, 200);
	mywindow.setWindowTitle("mywindow");
	mywindow.show();
// lat 4
	CWidget mywidget;
	mywidget.show();
// lat 5
	DWidget yourwidget;
	yourwidget.show();

// lat 6
	EWidget hiswidget;
	hiswidget.show();

	return app.exec();
}

